package sm.upgrade;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import sm.upgrade.api.UpgradePhase;
import sm.util.SMMap;

public class IcmenvMassUpdateUpgrade implements UpgradePhase {
	private static Logger logger = LoggerFactory.getLogger(UpgradePhase.class);

	private HibernateTemplate template;

	public void setTemplate(HibernateTemplate template) {
		this.template = template;
	}

	@Override
	public void upgrade() {
		logger.info("Updating db.mass.update field in icmenv records...");
		List<Object> icmenvs = template.find("from icmenv");
		if (icmenvs != null) {
			for (Object icmenv : icmenvs) {
				SMMap icmenvMap = (SMMap) icmenv;
				icmenvMap.put("db_mass_update", icmenvMap.get("mass_update"));
				icmenvMap.put("db_complex", icmenvMap.get("mass_update"));
				template.update("icmenv", icmenvMap);
			}
		}

		logger.info("  Finished updating db.mass.update field in icmenv records.");
	}

}
